<?php
class FriendsVo extends SzAbstractMySqlVo
{

    private $userId;
    private $friendsList;
    private $fansList;
    private $followingList;
    private $friendsCount;

    /**
     * Initialize FriendsVo.
     *
     * @param $userId
     * @param $friendsList
     * @param $fansList
     * @param $followingList
     * @param $friendsCount
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return FriendsVo
     */
    public function __construct($userId, $friendsList, $fansList, $followingList, $friendsCount, $isInsert = false) {
        $this->userId = $userId;
        $this->friendsList = json_decode($friendsList, true);
        $this->fansList = json_decode($fansList, true);
        $this->followingList = json_decode($followingList, true);
        $this->friendsCount = $friendsCount;

        $this->isInsert = $isInsert;
        $this->voClassName = 'FriendsVo';
        $this->ormName = 'Friends';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'friendsList' => ($needEncode) ? $this->getFriendsList() : $this->getRawFriendsList(),
            'fansList' => ($needEncode) ? $this->getFansList() : $this->getRawFansList(),
            'followingList' => ($needEncode) ? $this->getFollowingList() : $this->getRawFollowingList(),
            'friendsCount' => $this->getFriendsCount(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'friendsList' => ($needEncode) ? $this->getFriendsList() : $this->getRawFriendsList(),
            'fansList' => ($needEncode) ? $this->getFansList() : $this->getRawFansList(),
            'followingList' => ($needEncode) ? $this->getFollowingList() : $this->getRawFollowingList(),
            'friendsCount' => $this->getFriendsCount(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getFriendsList(),
            $this->getFansList(),
            $this->getFollowingList(),
            $this->getFriendsCount(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getFriendsList()
    {
        return json_encode($this->friendsList);
    }

    public function getRawFriendsList()
    {
        return $this->friendsList;
    }

    public function setFriendsList($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 21840) {
            SzLogger::get()->error('[FriendsVo] The length of column friendsList exceed the limit, length / limit: ' . $encodedLength . ' / 21840');
            throw new SzException(10522, array('FriendsVo', '21840', $encodedLength));
        } else if ($encodedLength > 19656) {
            SzLogger::get()->warn('[FriendsVo] The length of column friendsList exceed the warning level, length / limit: ' . $encodedLength . ' / 21840');
        }
        $this->saveColumnStatus(1, $this->friendsList);
        $this->friendsList = $val;
    }

    public function getFansList()
    {
        return json_encode($this->fansList);
    }

    public function getRawFansList()
    {
        return $this->fansList;
    }

    public function setFansList($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 21840) {
            SzLogger::get()->error('[FriendsVo] The length of column fansList exceed the limit, length / limit: ' . $encodedLength . ' / 21840');
            throw new SzException(10522, array('FriendsVo', '21840', $encodedLength));
        } else if ($encodedLength > 19656) {
            SzLogger::get()->warn('[FriendsVo] The length of column fansList exceed the warning level, length / limit: ' . $encodedLength . ' / 21840');
        }
        $this->saveColumnStatus(2, $this->fansList);
        $this->fansList = $val;
    }

    public function getFollowingList()
    {
        return json_encode($this->followingList);
    }

    public function getRawFollowingList()
    {
        return $this->followingList;
    }

    public function setFollowingList($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 21840) {
            SzLogger::get()->error('[FriendsVo] The length of column followingList exceed the limit, length / limit: ' . $encodedLength . ' / 21840');
            throw new SzException(10522, array('FriendsVo', '21840', $encodedLength));
        } else if ($encodedLength > 19656) {
            SzLogger::get()->warn('[FriendsVo] The length of column followingList exceed the warning level, length / limit: ' . $encodedLength . ' / 21840');
        }
        $this->saveColumnStatus(3, $this->followingList);
        $this->followingList = $val;
    }

    public function getFriendsCount()
    {
        return $this->friendsCount;
    }

    public function setFriendsCount($val)
    {
        $this->saveColumnStatus(4, $this->friendsCount);
        $this->friendsCount = $val;
    }

}